<?php
/**
 * Geneone: Content Management Framework
 * View Guest Information
 *
 * http://geneone.neondragon.net/
 *
 * @package Geneone
 * @author Khlo
 * @version 1.0
 * @copyright 2004-2006 Geneone Development Team
 */
 
require_once 'Gene/Object.php';
 
class Gene_Special_Guest {
	/**
	 * Default Action
	 */
	function main() {
		$tpl =& Gene::getTemplate();
		$db =& Gene::getDatabase();
		$user =& Gene::getUser();
		
		if ($user->hasPermission("namespaces.user.guest_info")) {
			$objectid = Gene_Request::getInteger("object", GENE_REQUEST_GET);
			if ($object =& Gene_Object::get($objectid) && $object->canModerate()) {
				$info = $object->get();
				$tpl->assign ("object", $info);
				
				$q = $db->prepare ("SELECT * FROM ".Gene::tableName("object_guests")." WHERE object_id=?");
				$res = $q->execute(array($info['object_id']));
				$guest = $res->fetchRow();
				$res->free();
				
				$tpl->assign("guest", $guest);
				
				$q = $db->prepare ("SELECT guest_name, COUNT(object_id) AS namecount FROM ".Gene::tableName("object_guests")." WHERE guest_ip=? GROUP BY guest_name ORDER BY namecount DESC");
				$res = $q->execute(array($guest['guest_ip']));
				$guestnames = $res->fetchAll();
				$res->free();
				
				$tpl->assign("guestnames", $guestnames);
				
				$q = $db->prepare ("SELECT * FROM ".Gene::tableName("objects")." o LEFT JOIN ".Gene::tableName("object_guests")." g ON (o.object_id=g.object_id) WHERE g.guest_email=? ORDER BY t_create DESC");
				$res = $q->execute(array($guest['guest_email']));
				$guestobjects = $res->fetchAll();
				$res->free();
				
				$tpl->assign("guestobjects", $guestobjects);
				
				$tpl->assign("finalbody", $tpl->fetch("special/guest"));
			} else {
				$tpl->assign("finalbody", $tpl->fetch("errors/permissionerror"));
			}
		} else {
			$tpl->assign("finalbody", $tpl->fetch("errors/permissionerror"));
		}
	}
}
?>